PR-1d: extract CudaRenderCtx from LoweringCtx (Phase T-1)#81
Merged
StarGazerM merged 1 commit intoMay 20, 2026
Merged
Conversation
Per docs/phase_decomposition_redesign.md section 3.2.1. The dialect-
level LoweringCtx historically carried both structural lowering
state (counters, lexical-scope flags, handle aliasing) and CUDA C++
identifier scratch (view var names, OutputContext vars, ballot
validity vars, etc.). This PR splits the second bucket into a
target-private CudaRenderCtx (src/srdatalog/ir/codegen/cuda/lower_ctx.py).
Extracted fields (10 total):
- view_var_names, output_var, output_var_overrides
- view_slot_bases, rel_index_types
- tiled_cartesian_valid_var, ws_cartesian_valid_var
- neg_pre_narrow, debug, tile_var
LoweringCtx exposes the render-private fields as forwarding
properties (back-compat seam per D20) so 100+ existing call sites
that say ctx.view_var_names keep working without an edit. The
constructor still accepts the legacy flat kwargs; a new
render_ctx= kwarg routes a pre-built CudaRenderCtx straight in.
NegPreNarrowInfo moves to the new module (its fields are all CUDA
identifier scratch) and is re-exported from lowerings/__init__.py
for back-compat.
Pragma-scratch booleans (is_counting, dedup_hash, tiled_cartesian,
ws_enabled, bg_enabled) stay on LoweringCtx — their removal is
scheduled for PR-1e. The framework-level LowerCtx (5 fields) at
src/srdatalog/ir/core/lower_ctx.py is untouched per D10.
Quality gates:
- pytest tests/ -x : 1689 passed, 7 skipped (was 1663+7;
26 new tests in test_cuda_render_ctx_extraction.py)
- byte-equivalence subset : 532 passed, 2 skipped
- mypy src/srdatalog/ : 147 errors (matches baseline; no regression)
- ruff check + format : clean
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
StarGazerM
added a commit
that referenced
this pull request
May 20, 2026
StarGazerM
added a commit
that referenced
this pull request
May 20, 2026
Replaces § 3.2.1 ("Split LoweringCtx from CudaRenderCtx") with
"Dissolve LoweringCtx (no-context principle)". Adds a sub-clause
to § 1 (ACID test) codifying the three-bucket discipline:
1. Cross-pass data → typed IR op
2. Intra-pass scratch → function-local / explicit kwarg
3. Services → immutable Services handle
Adds amendment-log entry § 10.2. Refers forward to discipline rule
D22 (strict monotonic decrease of ctx-field count; to be codified
in code_discipline.md per the standard cadence).
Triggered by user review of merged PR-1d (#81) which introduced
CudaRenderCtx with 10 fixed-schema fields — the same anti-pattern
the redesign is supposed to eliminate. PR-1d reverted in #82.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
StarGazerM
added a commit
that referenced
this pull request
May 20, 2026
Replaces § 3.2.1 ("Split LoweringCtx from CudaRenderCtx") with
"Dissolve LoweringCtx (no-context principle)". Adds a sub-clause
to § 1 (ACID test) codifying the three-bucket discipline:
1. Cross-pass data → typed IR op
2. Intra-pass scratch → function-local / explicit kwarg
3. Services → immutable Services handle
Adds amendment-log entry § 10.2. Refers forward to discipline rule
D22 (strict monotonic decrease of ctx-field count; to be codified
in code_discipline.md per the standard cadence).
Triggered by user review of merged PR-1d (#81) which introduced
CudaRenderCtx with 10 fixed-schema fields — the same anti-pattern
the redesign is supposed to eliminate. PR-1d reverted in #82.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fourth of 5 splits of the original PR-1. Phase T-1 per spec § 3.2.1 — extracts CUDA-render-private fields out of the dialect-level
LoweringCtxinto a newCudaRenderCtxundersrc/srdatalog/ir/codegen/cuda/lower_ctx.py.Extracted (10 fields)
view_var_names,output_var,output_var_overrides,view_slot_bases,rel_index_types,tiled_cartesian_valid_var,ws_cartesian_valid_var,neg_pre_narrow,debug,tile_varSpec § 3.2.1 listed 9; agent verified against the actual monolith.
dedup_hash_vars/ws_cartesian_bound_varslive on the legacyCodeGenContext, notLoweringCtx— documented + deferred to a later PR.Back-compat shape
CudaRenderCtxplain@dataclass(no__slots__, not frozen — BG test path uses dynamic setattr)LoweringCtx.render_ctx: CudaRenderCtxfield addedctx.<extracted_field>keep working unchanged via forwarding propertiesLoweringCtxis no longer@dataclass(it needed a custom__init__accepting both flat legacy kwargs andrender_ctx=; a dataclass field + property of the same name would collide). Behaves identically for external callers.NegPreNarrowInfomoved tocodegen/cuda/lower_ctx.py(its fields are pure CUDA C++ identifier scratch); re-exported fromlowerings/__init__.pyfor back-compat to avoid a circular-import dance.Test plan
Out of scope (later splits)
is_counting/dedup_hash/tiled_cartesian/ws_enabled/bg_enabledfrom both contexts)Zero conflict with PR-1c (#80)
PR-1c touches
Compiler.run,InitialProg.target,KernelCtx.target(none in this PR's diff). PR-1d toucheslower_ctx.py(NEW) +sorted_array/lowerings/__init__.py(file-disjoint).default_pipelines.pyleft untouched.🤖 Generated with Claude Code